//
//  systemInfoTools.m
//  GGProject
//
//  Created by yuemei on 2018/5/17.
//  Copyright © 2018年 yuemei. All rights reserved.
//

#import "systemInfoTools.h"
#import <sys/utsname.h>

@implementation systemInfoTools
static systemInfoTools *tools = nil;
+(instancetype)shareSystemInfoTools{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        tools = [[systemInfoTools alloc] init];
    });
    return tools;
}

+(NSString *)currentDeviceVersion{
    return [UIDevice currentDevice].systemVersion;
}

+(compareResult)compareCurrentVersionWithTarger:(double)targetVersion{
    double version = [systemInfoTools currentDeviceVersion].doubleValue;
    compareResult result = greaterThan;
    if (version > targetVersion) result = greaterThan;
    if (version < targetVersion) result = lessThan;
    if (version == targetVersion) result = equalTo;
    return result;
}

+(deviceType)deviceType{
    struct utsname systemInfo;
    
    uname(&systemInfo);
    
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
    deviceType type = iPhone2G;
    if([platform isEqualToString:@"iPhone1,1"]){
        platform = @"iPhone 2G";
        type = iPhone2G;
    }else if([platform isEqualToString:@"iPhone1,2"]){
        platform = @"iPhone 3G";
        type = iPhone3G;
    }else if([platform isEqualToString:@"iPhone2,1"]){
        platform = @"iPhone 3GS";
        type = iPhone3GS;
    }else if([platform isEqualToString:@"iPhone3,1"]){
        platform = @"iPhone 4";
        type = iPhone4;
    }else if([platform isEqualToString:@"iPhone3,2"]){
        platform = @"iPhone 4";
        type = iPhone4;
    }else if([platform isEqualToString:@"iPhone3,3"]){
        platform = @"iPhone 4";
        type = iPhone4;
    }else if([platform isEqualToString:@"iPhone4,1"]){
        platform = @"iPhone 4S";
        type = iPhone4S;
    }else if([platform isEqualToString:@"iPhone5,1"]){
        platform = @"iPhone 5";
        type = iPhone5;
    }else if([platform isEqualToString:@"iPhone5,2"]){
        platform = @"iPhone 5";
        type = iPhone5;
    }else if([platform isEqualToString:@"iPhone5,3"]){
        platform = @"iPhone 5c";
        type = iPhone5c;
    }else if([platform isEqualToString:@"iPhone5,4"]){
        platform = @"iPhone 5c";
        type = iPhone5c;
    }else if([platform isEqualToString:@"iPhone6,1"]){
        platform = @"iPhone 5s";
        type = iPhone5s;
    }else if([platform isEqualToString:@"iPhone6,2"]){
        platform = @"iPhone 5s";
        type = iPhone5s;
    }else if([platform isEqualToString:@"iPhone7,1"]){
        platform = @"iPhone 6 Plus";
        type = iPhone6Plus;
    }else if([platform isEqualToString:@"iPhone7,2"]){
        platform = @"iPhone 6";
        type = iPhone6;
    }else if([platform isEqualToString:@"iPhone8,1"]){
        platform = @"iPhone 6s";
        type = iPhone6s;
    }else if([platform isEqualToString:@"iPhone8,2"]){
        platform = @"iPhone 6s Plus";
        type = iPhone6sPlus;
    }else if([platform isEqualToString:@"iPhone8,4"]){
        platform = @"iPhone SE";
        type = iPhoneSE;
    }else if([platform isEqualToString:@"iPhone9,1"]){
        platform = @"iPhone 7";
        type = iPhone7;
    }else if([platform isEqualToString:@"iPhone9,2"]){
        platform = @"iPhone 7 Plus";
        type = iPhone7Plus;
    }else if([platform isEqualToString:@"iPhone10,1"]){
        platform = @"iPhone 8";
        type = iPhone8;
    }else if([platform isEqualToString:@"iPhone10,4"]){
        platform = @"iPhone 8";
        type = iPhone8;
    }else if([platform isEqualToString:@"iPhone10,2"]){
        platform = @"iPhone 8 Plus";
        type = iPhone8Plus;
    }else if([platform isEqualToString:@"iPhone10,5"]){
        platform = @"iPhone 8 Plus";
        type = iPhone8Plus;
    }else if([platform isEqualToString:@"iPhone10,3"]){
        platform = @"iPhone X";
        type = iPhoneX;
    }else if([platform isEqualToString:@"iPhone10,6"]){
        platform = @"iPhone X";
        type = iPhoneX;
    }else if([platform isEqualToString:@"i386"]){
        platform = @"iPhone模拟器";
        type = iPhoneSimulator;
    }else if([platform isEqualToString:@"x86_64"]){
        platform = @"iPhone模拟器";
        type = iPhoneSimulator;
    }
    return type;
//    return platform;
}
@end
